package com.tyx.www.mynotepad;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.EditText;

/**
 * Created by Administrator on 2016/6/23.
 */
public class EditActivity extends Activity {
    private EditText write;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;
    private String getName;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_notepad);
        Intent intent=getIntent();
        if(intent!=null)getName=intent.getStringExtra("Name");
        sharedPreferences=getSharedPreferences(getName,MODE_PRIVATE);
        findView();
        initView();
    }

    private void findView() {
        write= (EditText) findViewById(R.id.write);
    }

    private void initView() {

    }

    @Override
    protected void onPause() {
        super.onPause();
        editor=sharedPreferences.edit();
        editor.putString("Namewrite",write.getText().toString());
        editor.commit();
    }

    @Override
    protected void onResume() {
        super.onResume();
        write.setText(sharedPreferences.getString("Namewrite",""));
   }
}
